@extends('user.layouts.head')
@section('content')
    <body>
    <div id="app">
        <div class="wrapper -header-fixed">

        @include('user.layouts.navbar')
        @include('user.layouts.sidebar')

        <!-- 内容页开始-->
            <div class="content-container">
                <div class="container-fluid">
                    <div class="page-content">

                        <nav aria-label="breadcrumb">
                            <ol class="breadcrumb">
                                <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">仪表盘</a></li>
                                <li class="breadcrumb-item active" aria-current="page">横幅广告</li>
                            </ol>
                        </nav>

                        <div class="card">
                            <div class="card-body">
                                <div class="row">

                                    <div class="col-xl-3">
                                        <div class="card" style="margin-bottom: 10px">
                                            <div class="card-body">
                                                <h5 class="card-title"><b></b>{{ date('Y年n月')}}1日 横幅广告位</h5>
                                                <p class="card-text">
                                                    当前价格：<b class="text-danger"> {{$banner[0]->price}} 元</b><br/>
                                                    &nbsp;&nbsp;&nbsp;&nbsp;拥有者：<b
                                                        class="text-danger">{{$banner[0]->buyer != '' ? substr_replace($banner[0]->buyer,'***',2,3):''}}</b><br/>
                                                    结束日期：<b>{{ date('Y年n月t日', strtotime('-1 month')) }} 23:59:59</b>
                                                </p>
                                                <button class="btn btn-primary disabled">已停止购买</button>
                                            </div>
                                        </div>
                                    </div>

                                    @foreach($banner as $key => $data)
                                        @if ($key < date('t')+1 && $key > 0)
                                            <div class="col-xl-3">
                                                <div class="card" style="margin-bottom: 10px">
                                                    <div class="card-body">
                                                        <h5 class="card-title"><b></b>{{ date('Y年n月').($key+1)}}日 横幅广告位</h5>
                                                        <p class="card-text">
                                                            当前价格：<b class="text-danger"> {{$data->price}} 元</b><br/>
                                                            @if( date('n',strtotime($data->buy_time)) >= date('n'))
                                                                &nbsp;&nbsp;&nbsp;&nbsp;拥有者：<b class="text-danger">{{$data->buyer != '' ? substr_replace($data->buyer,'***',2,3):''}}</b><br/>
                                                            @else
                                                                &nbsp;&nbsp;&nbsp;&nbsp;拥有者：<br/>
                                                            @endif
                                                            结束日期：<b>{{date('Y年n月'.($key).'日')}} 23:59:59</b>
                                                        </p>
                                                        @if( $key < date('j') || $data->date_issue === (($key+1) <= 9 ? date('Ym').'0'.($key+1) : date('Ym').($key+1)) || $data->date_issue != '' && $data->date_issue > (($key+1) <= 9 ? date('Ym').'0'.($key+1) : date('Ym').($key+1)) )
                                                            <button class="btn btn-primary disabled">已停止购买</button>
                                                        @else
                                                            <button class="btn btn-primary" onclick="operation_tip2({{$key+1}})"> 立即购买 </button>
                                                        @endif
                                                    </div>
                                                </div>
                                            </div>
                                        @endif
                                    @endforeach

                                    <div class="col-xl-3">
                                        <div class="card" style="margin-bottom: 10px">
                                            <div class="card-body">
                                                <h5 class="card-title"><b></b>{{ date('Y年n月', strtotime('+1 month')) }} 1日 横幅广告位</h5>
                                                <p class="card-text">
                                                    当前价格：<b class="text-danger"> {{$banner[0]->price}} 元</b><br/>
                                                    @if( date('n',strtotime($banner[0]->buy_time)) >= date('n'))
                                                        &nbsp;&nbsp;&nbsp;&nbsp;拥有者：<b class="text-danger">{{$banner[0]->buyer != '' ? substr_replace($banner[0]->buyer,'***',2,3):''}}</b><br/>
                                                    @else
                                                        &nbsp;&nbsp;&nbsp;&nbsp;拥有者：<br/>
                                                    @endif
                                                    结束日期：<b>{{ date('Y年n月t日') }} 23:59:59</b>
                                                </p>
                                                @if( $banner[0]->date_issue < date('Ymd') && $banner[0]->date_issue != '')
                                                    <button class="btn btn-primary disabled">已停止购买</button>
                                                @else
                                                    <button class="btn btn-primary" onclick="operation_tip2()">立即购买</button>
                                                @endif
                                            </div>
                                        </div>
                                    </div>

                                </div> <!-- .row -->
                            </div> <!-- .card-body -->
                        </div> <!-- .card -->

                    </div> <!-- .page-content -->
                </div> <!-- .container-fluid -->
            </div> <!-- .content-container -->
        </div> <!-- .wrapper -->
    </div> <!-- #app -->

    <script src="{{ mix('js/app.js') }}"></script>
    <script src="{{ asset('/js/main.js') }}"></script>
    <script>

        let isLoading = false;

        // 购买提交
        function submit(day) {

            let date = new Date();
            let year = date.getFullYear();              // 从 Date 对象以四位数字返回年份。
            let month = date.getMonth() + 1;            // 从 Date 对象返回月份 (0 ~ 11)。
            let month2 = date.getMonth() + 2;           // 从 Date 对象返回月份 (0 ~ 11)。
            let dateIssue = 0;

            if (month < 10) {
                month = '0' + month;
            }

            if (month2 < 10) {
                month2 = '0' + month2;
            }

            if (month2 > 12) {
                month2 = 1;
            }

            if (day < 10) {
                day = '0' + day;
            }

            if (typeof day === 'undefined') {
                day = '01';
                dateIssue = year + '' + month2 + '01';
            } else {
                dateIssue = year + '' + month + '' + day;
            }

            if (isLoading === false) {
                isLoading = true;
                axios.post('{{ route('banner.store') }}', {
                    issue: day,
                    date_issue: dateIssue //日期
                })
                    .then(function (response) {
                        isLoading = false;
                        toast_tip2(response.data.message, '{{ route('banner.index') }}');
                    })
                    .catch(function (error) {
                        isLoading = false;
                        $.each(error.response.data.errors, function (index, object) {
                            toast(object[0]);
                            return false;
                        });
                    })
            }
        }

    </script>
    </body>

@endsection
